<template>
	<title-container @more="handleMore" :title="fragmentInfo.title" :needMore="needMore">
		<view class="course-list">
			<course-item class="item" v-for="(courseInfo, index) in courseInfoVoList" v-if="index < maxNumber" :key="index" :courseInfo="courseInfo"></course-item>
		</view>
	</title-container>
</template>

<script>
import titleContainer from '@/components/course/titleContainer'
import courseItem from '@/components/course/courseItem'
export default {
	components:{
		courseItem,
		titleContainer
	},
	props: {
		templateId: {
			type: Number,
			default: ''
		},
		params: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			fragmentInfo:{},
			courseInfoVoList:[],//课程列表
			searchCondition: {
				spuIdList:[],//课程的spuid列表
				productName:'',//商品名称
				courseCategoryIdList: [], //课程分类id列表
				courseLabelList: [], //课程标签id列表
				//搜索条件
				// sid:uni.getStorageSync('sessionId') || "",//会话id
				keyWord: '', //关键词
				minPrice: '', //最低价
				maxPrice: '', //最高价
				sortType: Number, //排序类型0：综合排序， 1：销量降序，2：更新时间， 3：价格升序， 4：价格降序
				needReturnSearchParam: 0, //	是	Integer	是否返回筛选条件 1-是，0-否
				pageNo: 1, //页码
				pageSize: 25, //页数
			},
			maxNumber:8
		};
	},
	computed:{
		needMore(){
			return this.courseInfoVoList.length > this.maxNumber?true:false
		}
	},
	created() {
		this.fragmentInfo = JSON.parse(this.params);
		this.init()
	},
	methods:{
		init(){
			switch (this.fragmentInfo.sourceType){
				case '208'://指定课程
				this.queryCourseListBySpuIdList();
					break;
				case '209'://课程分类
				this.searchCondition.courseCategoryIdList = this.fragmentInfo.sourceValue;
				this.queryCourseList();
					break;
				case '210'://课程标签
				this.searchCondition.courseLabelList = this.fragmentInfo.sourceValue;
				this.queryCourseList();
					break;
				case '211'://企业风采
				this.searchCondition.companyCourse = 1;//是否企业课程，0：否，1：是
				this.queryCourseList();
					break;
				default:
					break;
			}
		},//根据spuIpList获取课程数据
		queryCourseListBySpuIdList(){
			var searchCondition = {
				idList: this.fragmentInfo.sourceValue,//课程的spuid列表
				pageNo: 1, //页码
				pageSize: 25, //页数
			}
			var url = 'product/spu/list';
			this.$request(url, searchCondition).then(
				data => {
					this.courseInfoVoList = data.spuList;
				},
				error => {
				}
			);
		},//课程搜索
		queryCourseList(){
			var url = 'product/spu/pageCourseSpu';
			this.$request(url, this.searchCondition).then(
				data => {
					this.courseInfoVoList = data.courseInfoVoList;
				},
				error => {

				}
			);
		},
		handleMore() {
			var linkValue = JSON.stringify(this.fragmentInfo.sourceValue)
			this.$routeUtils.navigateTo({
				url: '/package_course/list/moreCourseList?linkType='+this.fragmentInfo.sourceType+'&linkValue=' + linkValue
			})
		}
	}
}
</script>

<style scoped lang="scss">
.course-list{
	margin-top: 24rpx;
	overflow: hidden;
	.item{
		float: left;
		margin-bottom: 20rpx;
	}
}
.course-list .item:nth-child(2n+1) {
	margin-right: 18rpx;
}
</style>
